home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 5 / Gekikoh Dennoh Club Vol. 5 (Japan).7z / Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin / internet / xip / iijppp.lzh / src / auth.c < prev    next >
C/C++ Source or Header  |  1994-10-10  |  3KB  |  111 lines

  1. /*
  2.  *            PPP Secret Key Module
  3.  *
  4.  *        Written by Toshiharu OHNO (tony-o@iij.ad.jp)
  5.  *
  6.  *   Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
  7.  *
  8.  * Redistribution and use in source and binary forms are permitted
  9.  * provided that the above copyright notice and this paragraph are
  10.  * duplicated in all such forms and that any documentation,
  11.  * advertising materials, and other materials related to such
  12.  * distribution and use acknowledge that the software was developed
  13.  * by the Internet Initiative Japan, Inc.  The name of the
  14.  * IIJ may not be used to endorse or promote products derived
  15.  * from this software without specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  17.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  18.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  *
  20.  *    TODO:
  21.  *        o Imprement check against with registerd IP addresses.
  22.  */
  23. #include "fsm.h"
  24. #include "ipcp.h"
  25.  
  26. extern FILE *OpenSecret();
  27. extern void CloseSecret();
  28.  
  29. int
  30. AuthValidate(fname, system, key)
  31. char *fname, *system, *key;
  32. {
  33.   FILE *fp;
  34.   int n;
  35.   char *vector[20];
  36.   char buff[200];
  37.   char passwd[100];
  38.  
  39.   fp = OpenSecret(fname);
  40.   if (fp == NULL)
  41.     return(0);
  42.   while (fgets(buff, sizeof(buff), fp)) {
  43.     if (buff[0] == '#')
  44.       continue;
  45.     buff[strlen(buff)-1] = 0;
  46.     bzero(vector, sizeof(vector));
  47.     n = MakeArgs(buff, &vector);
  48.     if (n < 2)
  49.       continue;
  50.     if (strcmp(vector[0], system) == 0) {
  51.       ExpandString(vector[1], passwd, 0);
  52.       if (strcmp(passwd, key) == 0) {
  53.     CloseSecret(fp);
  54.         bzero(&DefHisAddress, sizeof(DefHisAddress));
  55.         n -= 2;
  56.         if (n > 0) {
  57.       ParseAddr(n--, &vector[2],
  58.         &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
  59.     }
  60.     IpcpInit();
  61.     return(1);    /* Valid */
  62.       }
  63.     }
  64.   }
  65.   CloseSecret(fp);
  66.   return(0);        /* Invalid */
  67. }
  68.  
  69. char *
  70. AuthGetSecret(fname, system, len, setaddr)
  71. char *fname, *system;
  72. int len, setaddr;
  73. {
  74.   FILE *fp;
  75.   int n;
  76.   char *vector[20];
  77.   char buff[200];
  78.   static char passwd[100];
  79.  
  80.   fp = OpenSecret(fname);
  81.   if (fp == NULL)
  82.     return(NULL);
  83.   while (fgets(buff, sizeof(buff), fp)) {
  84.     if (buff[0] == '#')
  85.       continue;
  86.     buff[strlen(buff)-1] = 0;
  87.     bzero(vector, sizeof(vector));
  88.     n = MakeArgs(buff, &vector);
  89.     if (n < 2)
  90.       continue;
  91.     if (strlen(vector[0]) == len && strncmp(vector[0], system, len) == 0) {
  92.       ExpandString(vector[1], passwd, 0);
  93.       if (setaddr) {
  94.         bzero(&DefHisAddress, sizeof(DefHisAddress));
  95.       }
  96.       n -= 2;
  97.       if (n > 0 && setaddr) {
  98. #ifdef DEBUG
  99.     LogPrintf(LOG_LCP, "*** n = %d, %s\n", n, vector[2]);
  100. #endif
  101.     ParseAddr(n--, &vector[2],
  102.       &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
  103.     IpcpInit();
  104.       }
  105.       return(passwd);
  106.     }
  107.   }
  108.   CloseSecret(fp);
  109.   return(NULL);        /* Invalid */
  110. }
  111.